<template>
  <div class="overview-page">
    <h1>
      Welcome <strong>{{ userName }}</strong>
    </h1>
  </div>
</template>

<script setup lang="ts">
import { useLoginStore } from '@/store/login';
import { storeToRefs } from 'pinia';
import { computed } from 'vue';
import { storage } from '@/utils/storage-util';
import type { IUserInfo } from '@/types/login';

const loginStore = useLoginStore();
const { userInfo } = storeToRefs(loginStore);
const userName = computed(() => {
  const userObj = storage.get<IUserInfo>('userInfo', true) as IUserInfo | null;
  // 优先走缓存，速度会更快
  if (userObj) return userObj.name;
  else return userInfo.value?.name;
});
</script>

<style scoped lang="scss">
.overview-page {
  height: 100%;
  width: 100%;
  position: relative;

  h1 {
    font-family: 'JetBrains Mono ExtraBold';
    font-weight: 200;
    position: absolute;
    text-align: center;
    display: block;
    color: #252527;
    top: 50%;
    width: 100%;
    margin-top: -55px;
    text-transform: uppercase;
    letter-spacing: 1px;
    -webkit-transform-style: preserve-3d;
    -moz-transform-style: preserve-3d;
    transform-style: preserve-3d;
    -webkit-transform: translate3d(0, 0, 0);
    -moz-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 0;
    -webkit-animation: anim 3.2s ease-out forwards 1s;
    animation: anim 3.2s ease-out forwards 1s;
  }

  strong {
    display: block;
    font-weight: 400;
  }

  @-webkit-keyframes anim {
    0% {
      text-shadow: 0 0 50px #fff;
      letter-spacing: 80px;
      opacity: 0;
      -webkit-transform: rotateY(-90deg);
    }
    50% {
      text-shadow: 0 0 1px #fff;
      opacity: 0.8;
      -webkit-transform: rotateY(0deg);
    }
    75% {
      text-shadow: 0 0 1px #fff;
      opacity: 0.8;
      -webkit-transform: rotateY(0deg) translateZ(60px);
    }
    100% {
      text-shadow: 0 0 1px #fff;
      opacity: 0.8;
      letter-spacing: 8px;
      -webkit-transform: rotateY(0deg) translateZ(100px);
    }
  }
  @keyframes anim {
    0% {
      text-shadow: 0 0 50px #fff;
      letter-spacing: 80px;
      opacity: 0;
      -moz-transform: rotateY(-90deg);
    }
    50% {
      text-shadow: 0 0 1px #fff;
      opacity: 0.8;
      -moz-transform: rotateY(0deg);
    }
    75% {
      text-shadow: 0 0 1px #fff;
      opacity: 0.8;
      -moz-transform: rotateY(0deg) translateZ(60px);
    }
    100% {
      text-shadow: 0 0 1px #fff;
      opacity: 0.8;
      letter-spacing: 8px;
      -moz-transform: rotateY(0deg) translateZ(100px);
    }
  }
}
</style>
